#ifndef __FLASH_H__
#define __FLASH_H__
#include "stm32f10x.h"

typedef enum {
    FLASH_OP_DONE,
    FLASH_OP_ZERO,
    FLASH_OP_BUSY,
    FLASH_OP_FAIL,
} FlashOpEnum;

#define FLASH_MAXBYTE	            1024*1024

#define	WREN_FLASH					0x06
#define WRDI_FLASH					0x04
#define	RDID_FLASH					0x9F
#define	RDSR_FLASH					0x05
#define	WRSR_FLASH					0X01
#define	READ_FLASH					0X03
#define FAST_READ_FLASH			    0x0B
#define PP		        			0x02
#define SE							0xD8
#define	BE							0xC7
#define DP							0xB9
#define RES							0xAB

void flash_gpio_init(void);
void flash_spi_init(void);
void flash_init(void);
uint8_t flash_spi_read(void);
void flash_spi_write(uint8_t byte);

uint8_t flash_read_busy(void);
uint8_t flash_read_state(void);
uint8_t flash_write_state(uint8_t data);
uint8_t flash_write_enable(void);
uint8_t flash_read_busy(void);

uint32_t flash_read_id(void);
uint8_t flash_write_data(uint8_t sector_addr, uint8_t page_addr,
        uint8_t byte_addr, uint16_t num, uint8_t *data);
uint8_t flash_read_data(uint8_t sector_addr, uint8_t page_addr,
        uint8_t byte_addr, uint16_t num, uint8_t *data);
uint8_t flash_erase_sector(uint8_t sector_addr);
uint8_t flash_erase_all(void);


#endif
